package com.ruoyi.warehouse.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.CodeClient;
import com.ruoyi.warehouse.domain.CkWarehouse;
import com.ruoyi.warehouse.domain.WldaMaterialFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.warehouse.domain.LlrkIncomingMaterialStorage;
import com.ruoyi.warehouse.service.ILlrkIncomingMaterialStorageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 来料入库Controller
 * 
 * @author ruoyi
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/llrk")
public class LlrkIncomingMaterialStorageController extends BaseController
{
    @Autowired
    private ILlrkIncomingMaterialStorageService llrkIncomingMaterialStorageService;

    /**
     * 查询来料入库列表
     */
    @RequiresPermissions("warehouse:llrk:list")
    @GetMapping("/list")
    public TableDataInfo list(LlrkIncomingMaterialStorage llrkIncomingMaterialStorage)
    {
        startPage();
        List<LlrkIncomingMaterialStorage> list = llrkIncomingMaterialStorageService.selectLlrkIncomingMaterialStorageList(llrkIncomingMaterialStorage);
        return getDataTable(list);
    }

    /**
     * 导出来料入库列表
     */
    @RequiresPermissions("warehouse:llrk:export")
    @Log(title = "来料入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LlrkIncomingMaterialStorage llrkIncomingMaterialStorage)
    {
        List<LlrkIncomingMaterialStorage> list = llrkIncomingMaterialStorageService.selectLlrkIncomingMaterialStorageList(llrkIncomingMaterialStorage);
        ExcelUtil<LlrkIncomingMaterialStorage> util = new ExcelUtil<LlrkIncomingMaterialStorage>(LlrkIncomingMaterialStorage.class);
        util.exportExcel(response, list, "来料入库数据");
    }

    /**
     * 获取来料入库详细信息
     */
    @RequiresPermissions("warehouse:llrk:query")
    @GetMapping(value = "/{llCode}")
    public AjaxResult getInfo(@PathVariable("llCode") String llCode)
    {
        return success(llrkIncomingMaterialStorageService.selectLlrkIncomingMaterialStorageByLlCode(llCode));
//        return null;
    }

    /**
     * 新增来料入库
     */
    @RequiresPermissions("warehouse:llrk:add")
    @Log(title = "来料入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LlrkIncomingMaterialStorage llrkIncomingMaterialStorage)
    {
        return toAjax(llrkIncomingMaterialStorageService.insertLlrkIncomingMaterialStorage(llrkIncomingMaterialStorage));
    }

    /**
     * 修改来料入库
     */
    @RequiresPermissions("warehouse:llrk:edit")
    @Log(title = "来料入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LlrkIncomingMaterialStorage llrkIncomingMaterialStorage)
    {
        return toAjax(llrkIncomingMaterialStorageService.updateLlrkIncomingMaterialStorage(llrkIncomingMaterialStorage));
    }

    /**
     * 删除来料入库
     */
    @RequiresPermissions("warehouse:llrk:remove")
    @Log(title = "来料入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{llCodes}")
    public AjaxResult remove(@PathVariable String[] llCodes)
    {
        return toAjax(llrkIncomingMaterialStorageService.deleteLlrkIncomingMaterialStorageByLlCodes(llCodes));
    }

    /**
     * 审核
     *
     * @param llCode 审核
     * @return 结果
     */
    @RequiresPermissions("warehouse:llrk:examine")
    @PostMapping("/examine/{llCode}")
    public AjaxResult examine(@PathVariable String llCode)
    {
//        return toAjax(llrkIncomingMaterialStorageService.deleteLlrkIncomingMaterialStorageByLlCodes(llCodes));
        return toAjax(llrkIncomingMaterialStorageService.insertCkxqStorage(llCode));
    }

    /**
     * 撤销
     *
     * @param llCode 撤销
     * @return 结果
     */
    @PostMapping("/cancel/{llCode}")
    public AjaxResult cancel(@PathVariable String llCode)
    {
        return toAjax(llrkIncomingMaterialStorageService.cancel(llCode));
    }

    /**
     * 查询物料信息
     */
    @GetMapping("/wlList")
    public TableDataInfo wlList(WldaMaterialFile wldaMaterialFile)
    {
        startPage();
        List<WldaMaterialFile> list = llrkIncomingMaterialStorageService.selectWldaMaterialFile(wldaMaterialFile);
        return getDataTable(list);
    }

    /**
     * 查询仓库信息
     */
    @GetMapping("/ckList")
    public TableDataInfo ckList(CkWarehouse ckWarehouse)
    {
        startPage();
        List<CkWarehouse> list = llrkIncomingMaterialStorageService.selectCkWarehouse(ckWarehouse);
        return getDataTable(list);
    }

}
